package com.tianjian.oa.system;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.tianjian.common.BaseAction;
import com.tianjian.common.Criteria;
import com.tianjian.oa.system.pojos.Department;
import com.tianjian.oa.system.services.DepartmentService;

/**
 * @author 胡正衛
 */
public class DepartmentAction extends BaseAction {

	private static final long serialVersionUID = 2121889677854529433L;

	@Autowired
	private DepartmentService departmentService;

	/** 科室信息 */
	private Department department;

	/** 前台获取到的BH */
	private String bh;

	/** 定义action */
	public DepartmentAction() {
		super("科室管理");
	}

	@Override
	public String index() {
		return SUCCESS;
	}

	/* (non-Javadoc)
	 * @see com.tianjian.system.BaseAction#view()
	 */
	@Override
	public String view() {
		return SUCCESS;
	}

	@Override
	public String get() {
		Criteria criteria = new Criteria();
		inversionCriteria(criteria);
		List<Department> rows = departmentService.getData(criteria);
		this.result.put("rows", rows);
		return JSON;
	}

	/**
	 * 	打开添加页面
	 * */
	@Override
	public String add() {
		if (departmentService.insert(department) > 0) {
			result.put("result", 1);
		} else {
			result.put("result", -1);
		}
		return JSON;
	}

	/**
	 * 	打开编辑科室界面
	 * */
	@Override
	public String edit() {
		if (departmentService.update(department) > 0) {
			result.put("result", 1);
		} else {
			result.put("result", -1);
		}
		return JSON;
	}

	/**
	 * 	通过科室编号删除
	 * */
	@Override
	public String del() {
		if (departmentService.delete(bh) > 0) {
			result.put("result", 1);
		} else {
			result.put("result", -1);
		}
		return JSON;
	}

	public void setBh(String bh) {
		this.bh = bh;
	}

	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

}
